package net.lab1024.smartadmin.module.support.imgFile.controller;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.lab1024.smartadmin.common.controller.BaseController;
import net.lab1024.smartadmin.common.domain.PageResultDTO;
import net.lab1024.smartadmin.common.domain.ResponseDTO;
import net.lab1024.smartadmin.common.domain.ValidateList;
import net.lab1024.smartadmin.module.business.scenicSpot.dao.ScenicSpotDao;
import net.lab1024.smartadmin.module.business.scenicSpot.service.ScenicSpotService;
import net.lab1024.smartadmin.module.support.imgFile.domain.dto.ImgFileAddDTO;
import net.lab1024.smartadmin.module.support.imgFile.domain.dto.ImgFileQueryDTO;
import net.lab1024.smartadmin.module.support.imgFile.domain.dto.ImgFileUpdateDTO;
import net.lab1024.smartadmin.module.support.imgFile.domain.vo.ImgFileExcelVO;
import net.lab1024.smartadmin.module.support.imgFile.domain.vo.ImgFileUploadVO;
import net.lab1024.smartadmin.module.support.imgFile.domain.vo.ImgFileVO;
import net.lab1024.smartadmin.module.support.imgFile.service.ImgFileService;
import org.apache.poi.ss.usermodel.Workbook;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * [  ]
 *
 * @author wldd
 * @version 1.0
 * @company 图片
 * @copyright (c)  图片Inc. All rights reserved.
 * @date 2020-12-29 20:51:26
 * @since JDK1.8
 */
@RestController
@Api(tags = {""})
@RequestMapping("imgFile")
public class ImgFileController extends BaseController {

    @Autowired
    private ImgFileService imgFileService;


    @ApiOperation(value = "文件阿里云上传", notes = "文件阿里云上传")
    @PostMapping("fileUpload/{moduleType}")
    public ResponseDTO<ImgFileUploadVO> fileUpload(MultipartFile file, @PathVariable Integer moduleType) throws Exception {
        return imgFileService.fileUpload(file, moduleType);
    }


    @ApiOperation(value = "分页查询",notes = "@author wldd")
    @PostMapping("/page/query")
    public ResponseDTO<PageResultDTO<ImgFileVO>> queryByPage(@RequestBody ImgFileQueryDTO queryDTO) {
        return imgFileService.queryByPage(queryDTO);
    }

    @ApiOperation(value = "添加",notes = "@author wldd")
    @PostMapping("/add")
    public ResponseDTO<String> add(@RequestBody @Validated ImgFileAddDTO addTO){
        return imgFileService.add(addTO);
    }

    @ApiOperation(value="修改",notes = "@author wldd")
    @PostMapping("/update")
    public ResponseDTO<String> update(@RequestBody @Validated ImgFileUpdateDTO updateDTO){
        return imgFileService.update(updateDTO);
    }

    @ApiOperation(value="批量删除",notes = "@author wldd")
    @PostMapping("/deleteByIds")
    public ResponseDTO<String> delete(@RequestBody @Validated ValidateList<Long> idList) {
        return imgFileService.deleteByIds(idList);
    }

    @ApiOperation(value = "批量导出", notes = "@author wldd")
    @PostMapping("/export/batch")
    public void batchExport(@RequestBody @Validated ValidateList<Long> idList, HttpServletResponse response) {
        //查询数据
        List<ImgFileExcelVO> imgFileList = imgFileService.queryBatchExportData(idList);
        //导出操作
        ExportParams ex = new ExportParams("", "Sheet1");
        Workbook workbook = ExcelExportUtil.exportExcel(ex, ImgFileExcelVO.class, imgFileList);
        downloadExcel("", workbook, response);
    }

    @ApiOperation(value = "导出全部", notes = "@author wldd")
    @PostMapping("/imgFile/export/all")
    public void exportAll(@RequestBody @Validated ImgFileQueryDTO queryDTO, HttpServletResponse response) {
        //查询数据
        List<ImgFileExcelVO> imgFileList = imgFileService.queryAllExportData(queryDTO);
        //导出操作
        ExportParams ex = new ExportParams("", "Sheet1");
        Workbook workbook = ExcelExportUtil.exportExcel(ex, ImgFileExcelVO.class, imgFileList);
        downloadExcel("", workbook, response);
    }

}
